package com.ost.kautilya.modeling;

import java.util.Comparator;
import java.util.TreeMap;

public class ModelConfiguration extends TreeMap<ModelConfigurationParameter, String> {
	private static final long serialVersionUID = 1L;
	private final static Comparator<ModelConfigurationParameter> mComp = new Comparator<ModelConfigurationParameter>() {
		@Override
		public int compare(ModelConfigurationParameter p1, ModelConfigurationParameter p2) {
			return p1.compareTo(p2);
		}
	};

	public ModelConfiguration() {
		super(mComp);
	}

	public void setParameter(String param, String value) {
		for (ModelConfigurationParameter ps : keySet()) {
			if (ps.getApplicableName().equals(param)) {
				if (value == null || "".equals(value))
					remove(ps);
				else
					put(ps, value);
				break;
			}
		}
	}

	public String getParameter(String param) {
		for (ModelConfigurationParameter ps : keySet()) {
			if (ps.getApplicableName().equals(param)) {
				return get(ps);
			}
		}
		return null;
	}
	
	public String getDefinitionFor (ModelMetaData meta) {
		return meta.toString();
	}
}
